const url = "http://jsonplaceholder.typicode.com/posts";  //支持跨域访问的数据接口

let ul = document.querySelector("ul");

let xhr = new XMLHttpRequest();

xhr.open("GET", url);
xhr.send();

xhr.onreadystatechange = function () {
    //http状态码 200表示成功访问，403 404 50x
    if (xhr.readyState === 4 && xhr.status === 200) {

        let data = JSON.parse(xhr.responseText);
        console.log(data.length);

        for (let i = 0; i < data.length; i++) {
            const element = data[i];
            console.log(element.title);
            let li = document.createElement("li");
            li.textContent = element.title;
            ul.appendChild(li);
        }
    }
}